package org.lanqiao.api.product;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.CategoryPOJO;
import org.lanqiao.pojo.PageModel;
import org.lanqiao.service.ProductServiceImpl;

/**
 * Servlet implementation class SaleNumServlet
 */
/**
 *  同类型按销量排序，且分页 传入参数catename类名，page页数，pagesize页面大小 返回商品所有信息及销量（）salenum），页面大小和总页数
 * @author luqian1000
 *
 */
@WebServlet("/api/product/salenum")
public class SaleNumServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CategoryPOJO cate=new CategoryPOJO();
		cate.setName(request.getParameter("catename"));
		String page=request.getParameter("page");
		String pagesize=request.getParameter("pagesize");
		JsonResult result=null;
		try {
			ProductServiceImpl productService=new ProductServiceImpl();
			PageModel<List> list=productService.saleNumService(cate,page,pagesize);
			if(list!=null) {
				result=new JsonResult("查询成功",Constants.STATUS_SUCCESS,list);
			}else {
				result=new JsonResult("查询失败",Constants.STATUS_UNFOUND);
			}
		}catch(Exception e){
			result=new JsonResult("查询异常",Constants.STATUS_FAILURE);
		}
		JsonResultWriter.writer(response,result);
	}

	

}
